package core.bmp;

import java.io.File;
import java.io.IOException;

import core.bmp.model.BmpData;
import core.bmp.utils.BmpUtils;
import core.bmp.utils.IntegerUtil;

public abstract class AbsWorker {

	protected void start() throws IOException {
		String name = getClass().getSimpleName();

		File img = onPrepareImageFile();
		BmpData srcData = BmpUtils.loadBmp(img);
		System.out.println("加载图片:" + img.getPath());
		onWork(srcData);

		File savedImg = new File(Bmp.DIR_FILE, name + ".bmp");
		BmpUtils.saveBmp(srcData, savedImg);
		System.out.println("保存成功:" + savedImg.getPath());
	}

	/* 内部回调 */

	protected abstract File onPrepareImageFile();

	protected abstract void onWork(BmpData bmpData);

	/* 像素处理 */

	protected static int getGray(int argb) {
		return IntegerUtil.byteToUnsignedInt((byte) (argb & 0xFF));
	}

}
